Page({
  data: {
    username: '',
    password: ''
  },
  handleInputChange1(e) {
    // console.log(e);
    this.setData({
      username: e.detail.value
    });
  },
  handleInputChange2(e) {
    // console.log(e);
    this.setData({
      password: e.detail.value
    });
  },
  handleLogin() {
    wx.request({
      url: 'http://localhost:3001/login',
      method: 'POST',
      header: {
        'Content-Type': 'application/json' 
    },
      data: {
        username: this.data.username,
        password: this.data.password
      },
      success: (res) => {
        console.log(res.data);
        if (res.statusCode === 200) {
          wx.setStorageSync('token', res.data.token);
          wx.showToast({
            title: '登录成功',
            icon: 'success'
          });
          wx.switchTab({
            url: '/pages/sign/sign'
          });
        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none'
          });
        }
      }
    });
  }
});
